package com.tahado.service;


import java.util.Map;

import org.apache.commons.codec.binary.Base64; 
import com.restfb.*;

//import org.codehaus.jackson.map.ObjectMapper;

public class FacebookWrapper {
	
	 public static String fetchUser(String MY_ACCESS_TOKEN){
		 
		 FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
		 
		 com.restfb.types.User user = facebookClient.fetchObject("me", com.restfb.types.User.class);
		 
	 
	 return user.getName();
	 }


/*
	        // http://developers.facebook.com/docs/authentication/canvas 
	public static        Map<String, String> validateSignature(String signed_request, String 
	appSecret) throws Exception { 
	                if (signed_request == null) 
	                        throw new Exception("Invalid signature."); 
	                String[] parts = signed_request.split("\\."); 
	                if (parts.length != 2) 
	                        throw new Exception("Invalid signature."); 
	                String encSig = parts[0]; 
	                String encPayload = parts[1]; 
	                Base64 decoder = new Base64(true); 
	                Map<String, String> data; 
	                try { 
	                        data = new ObjectMapper().readValue(new 
	String(decoder.decode(encPayload)), HashMap.class); 
	                } catch (IOException e) { 
	                        throw new Exception("Failed to parse JSON session.", e); 
	                } 
	                try { 
	                        Mac mac = Mac.getInstance("HMACSHA256"); 
	                        mac.init(new SecretKeySpec(appSecret.getBytes(), 
	mac.getAlgorithm())); 
	                        byte[] calcSig = mac.doFinal(encPayload.getBytes()); 
	                        if (Arrays.equals(decoder.decode(encSig), calcSig)) 
	                                return data; 
	                        else 
	                                return null; 
	                } catch (InvalidKeyException e) { 
	                        throw new Exception("Failed to perform crypt operation.", e); 
	                } 
	        } 
*/
}
